package com.wedo.mall.adapter;

import android.content.Context;
import android.support.v4.util.ArrayMap;
import android.widget.TextView;

import com.e.library.adapter.Adapter;
import com.wedo.mall.R;
import com.wedo.mall.entity.Attr;
import com.wedo.mall.entity.AttrItem;
import com.wedo.mall.widget.AttrView;

import java.util.List;

/**
 * Created by e on 2017/7/13.
 */

public class AttrAdapter extends Adapter<Attr> {

    private ArrayMap<Attr,AttrItem> mSelected = new ArrayMap<>();
    public AttrAdapter(Context context, List<Attr> datas) {
        super(context, datas);
    }

    @Override
    protected int layout() {
        return R.layout.item_attr;
    }

    @Override
    protected void bind(EHolder holder, Attr attr, int position) {
        TextView tv_name = holder.find(R.id.tv_name);
        AttrView av_attr = holder.find(R.id.av_attr);
        tv_name.setText(attr.attr_name);
        av_attr.selected(mSelected).listener(onAttrChanged).attr(attr);
    }

    public ArrayMap<Attr,AttrItem> selected(){
        return mSelected;
    }

    private OnAttrChanged onAttrChanged;
    public void setOnAttrChanged(OnAttrChanged onAttrChanged){
        this.onAttrChanged = onAttrChanged;
    }

    public interface OnAttrChanged{
        void selected(ArrayMap<Attr,AttrItem> map);
    }
}
